package com.model.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

import java.text.SimpleDateFormat;
import java.util.Calendar;

@Setter
public class SignedSearchDTO {

    @Getter
    private String doctorId;

    @Getter
    private String ageRange;

    @Getter
    private String sex;

    private int ageTopRange;

    private int ageBottomRange;

    public int getAgeTopRange(){
        int ageTop = Integer.parseInt(ageRange.split("-")[1]);
        Calendar earlist = Calendar.getInstance();
        earlist.add(Calendar.YEAR, -ageTop);

        SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
        String dateStr = fmt.format(earlist.getTime());
        return Integer.parseInt(dateStr);
    }

    public int getAgeBottomRange(){
        int ageBottom = Integer.parseInt(ageRange.split("-")[0]);
        Calendar oldlist = Calendar.getInstance();
        oldlist.add(Calendar.YEAR, -ageBottom);

        SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
        String dateStr = fmt.format(oldlist.getTime());
        return Integer.parseInt(dateStr);
    }
}
